fragment TankTypeAttributes on _E_TankType{
  id
  __typename
  name
  minVal
  maxVal
  measure{
    id
    __typename
    name
  }
}

query searchTankType{
  searchTankType{
    elems {
      ...TankTypeAttributes
    }
  }
}

fragment TankAttributes on _E_Tank {
  id
  __typename
  tankOpenDate
  currentVal
  location{
    latitude
    longitude
  }
  tankType{
    id
    name
  }
  owner{
    entityId
  }
}

query searchTank($cond: String) {
  searchTank(cond: $cond) {
    elems {
      ...TankAttributes
    }
  }
}

mutation createTank($input: _CreateTankInput!) {
  packet {
    createTank(input: $input) {
      ...TankAttributes
    }
  }
}

mutation updateTank($input: _UpdateTankInput!) {
  packet {
    updateTank(input: $input) {
      ...TankAttributes
    }
  }
}

mutation deleteTank($id: ID!) {
  packet {
    deleteTank(id:$id)
  }
}

fragment TankOperationAttributes on _E_TankOperation {
  id
  __typename
  kind
  val
  transfer{
    entityId
  }
  aggregateRoot{
    id
  }
}

query searchTankOperation($cond: String) {
  searchTankOperation(cond: $cond) {
    elems {
      ...TankOperationAttributes
    }
  }
}

mutation increaseTankVal($tankId:ID! $val:BigDecimal!, $transferRef:_SingleReferenceInput){
  packet{  
    
    updateTank(input:{id:$tankId}
      inc:{
      	currentVal:{value:$val}
    	}
    ){
      id
      __typename
      currentVal
    }
    
    createTankOperation(input:{
      tank:$tankId
      val:$val
      kind:INPUT
      transfer:$transferRef
    }){
      ...TankOperationAttributes
    }
    
  }
}

mutation decreaseTankVal($tankId:ID! $val:BigDecimal!, $transferRef:_SingleReferenceInput){
  packet{  
    
    updateTank(input:{id:$tankId}
      inc:{
      	currentVal:{
          value:$val
          negative:true
        }
    	}
    ){
      id
      __typename
      currentVal
    }
    
    createTankOperation(input:{
      tank:$tankId
      val:$val
      kind:OUTPUT
      transfer:$transferRef
    }){
      ...TankOperationAttributes
    }
  }
}